<template>
  <el-dialog
    class="publish-dialog"
    :align-center="true"
    v-model="dialogVisible"
    :show-close="false"
    :lock-scroll="false"
  >
    <div class="title">您即将离开本平台前往</div>
    <div class="desc-main">
      <span class="web-url">{{ linkUrl }}</span>
      <span class="dev-line"></span>
      <span class="web-info">
        本平台不对该网站内容及真实性负责，请注意保护账号和隐私信息
      </span>
    </div>
    <div class="footer">
      <div class="left">
        <span class="red">{{ countTime }}</span>
        秒后自动访问该网站
      </div>
      <span class="cancel" @click="cancelJump"> 取消跳转 </span>
      <span class="goto-btn flex-item-c" @click="gotoPage"> 继续访问 </span>
    </div>
  </el-dialog>
</template>
<script lang="ts" setup>
import { ref, onBeforeUnmount, defineProps } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
const props = defineProps({
  linkUrl: {
    type: String,
    default: '',
  },
});
const emit = defineEmits(['isOk']);

const dialogVisible = ref<boolean>(false);
const automaticSkip = ref<boolean>(true);
const outInterVal = ref();
const countTime = ref(5);

const init = () => {
  countTime.value = 5;
  dialogVisible.value = true;
  outInterVal.value = setInterval(() => {
    countTime.value--;
    if (countTime.value <= 0) {
      countTime.value = 0;
      clearInterval(outInterVal.value);
      if (automaticSkip.value) gotoPage();
    }
  }, 1000);
};
const cancelJump = () => {
  automaticSkip.value = false;
  clearInterval(outInterVal.value);
  dialogVisible.value = false;
};

const gotoPage = () => {
  dialogVisible.value = false;
  const routeObj = {
    name: 'IframeSitePage',
    query: {
      url: props.linkUrl,
      name: '',
    },
  };
  router.push(routeObj);
};
defineExpose({
  init,
});
onBeforeUnmount(() => {
  clearInterval(outInterVal.value);
});
</script>
<style lang="scss">
.my-cascader .el-cascader-panel {
  font-size: 18px;
}
.publish-dialog {
  width: auto;
  border-radius: 8px;
  .el-dialog__header {
    display: none;
  }
  .el-dialog__body {
    min-height: auto;
    padding: 44px;
  }
  .title {
    margin-top: 4px;
    font-weight: bold;
    font-size: 28px;
    color: #222222;
    line-height: 28px;
  }
  .desc-main {
    background: #f8f8f8;
    border-radius: 4px;
    padding: 28px;
    margin-top: 33px;
    display: flex;
    flex-direction: column;
    .web-url {
      margin-bottom: 28px;
      font-weight: 500;
      font-size: 22px;
      color: #555555;
      line-height: 22px;
    }
    .dev-line {
      height: 2px;
      background: #e5e6e8;
      margin-bottom: 28px;
    }
    .web-info {
      font-weight: 500;
      font-size: 20px;
      color: #999999;
      line-height: 20px;
    }
  }
  .footer {
    display: flex;
    align-items: center;
    margin-top: 42px;
    font-family: PingFangSC, PingFang SC;
    zoom: 1;
    &::after {
      content: '';
      clear: both;
      display: block;
    }
    .left {
      float: left;
      font-weight: 500;
      font-size: 20px;
      line-height: 20px;
      color: #999999;
      .red {
        color: #ff1818;
      }
    }
    .cancel {
      flex: 1;
      margin-left: 40px;
      font-weight: 500;
      font-size: 20px;
      color: #0b6eff;
      line-height: 20px;
    }
    .goto-btn {
      height: 44px;
      float: right;
      position: relative;
      padding: 7px 22px;
      font-weight: 400;
      font-size: 20px;
      color: #ffffff;
      background: #0b6eff;
      border-radius: 4px;
      cursor: pointer;
      user-select: none;
    }
  }
}
.flex-item-c {
  display: flex;
  align-items: center;
}
</style>
